import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/Home',
    children: [{
      path: 'Home',
      name: 'Home',
      component: () => import('@/views/Home/index.vue'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },
  
  {
    path:'/acl',
    name:'Acl',
    component:()=> import("@/layout/index.vue"),
    meta:{
      title:"权限管理",
      icon:"el-icon-setting"
    },
    children:[
      {
        name: "User",
        path: "/acl/user/list",
        component: () => import("@/views/acl/user/index.vue"),
        meta: {
          title: "用户管理",
        },
      },
      {
        name: "Role",
        path: "/acl/role/list",
        component: () => import("@/views/acl/role/index.vue"),
        meta: {
          title: "角色管理",
        },
      },
      {
        name: "Permission",
        path: "/acl/permission/list",
        component: () => import("@/views/acl/permission/index.vue"),
        meta: {
          title: "菜单管理",
        },
      },
    ]
  },
  {
    path: '/Product',
    name: 'Product',
    component: () => import("@/layout/index.vue"),
    meta: {
      title: "商品管理",
      icon: "el-icon-s-goods",
    },
    children: [
      {
        path: "Trademark/list",
        name: "Trademark",
        component: () => import("@/views/Product/Trademark/index.vue"),
        meta: {
          title: "品牌管理",
        },
      },
      {
        path: "Attr/list",
        name: "Attr",
        component: () => import("@/views/Product/Attr/index.vue"),
        meta: {
          title: "平台属性管理",
        },
      },
      {
        path: "Sku/list",
        name: "Sku",
        component: () => import("@/views/Product/Sku/index.vue"),
        meta: {
          title: "Sku管理",
        },
      },
      {
        path: "Spu/list",
        name: "Spu",
        component: () => import("@/views/Product/Spu/index.vue"),
        meta: {
          title: "Spu管理",
        },
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
